'''
Created on Mar 17, 2010

@author: christianp
'''
import xml.sax.handler
from BruTile.Extent import Extent

class XMLLayerParser(xml.sax.handler.ContentHandler):
    '''
    classdocs
    '''
    tile_seed = None
    
    def __init__(self):
        
        '''
        Constructor
        '''
    
    def startElement(self, name, attributes):
        if name == "BoundingBox":
            minx = float(attributes.get("minx",""))
            #print("minx = " + str(minx))
            maxx = float(attributes.get("maxx",""))
            miny = float(attributes.get("miny",""))
            maxy = float(attributes.get("maxy",""))
            self.tile_seed.tile_schema.extent = Extent(minx, miny, maxx, maxy)
            #self.tile_seed.tile_schema.extent._print("XMLLayerParser:")
        elif name == "Origin":
            self.tile_seed.tile_schema.origin_x = float(attributes.get("x",""))
            self.tile_seed.tile_schema.origin_y = float(attributes.get("y",""))
            
            self.tile_seed.tile_schema.origin_y = (self.tile_seed.tile_schema.origin_y * -1)
            #self.tile_seed.tile_schema.origin_y = (self.tile_seed.tile_schema.origin_y)
            #print("originx = " + str(self.tile_seed.tile_schema.origin_x))
            #print("originy = " + str(self.tile_seed.tile_schema.origin_y))
        elif name == "TileFormat":
            self.tile_seed.tile_schema.width = int(attributes.get("width",""))
            self.tile_seed.tile_schema.height = int(attributes.get("height",""))
            self.tile_seed.tile_schema.format = str(attributes.get("extension",""))
        elif name == "TileSet":
            #print(str(float(attributes.get("units-per-pixel",""))))
            values = [int(attributes.get("order","")),float(attributes.get("units-per-pixel",""))]
            self.tile_seed.tile_schema.resolutions.append(values)

    def characters(self, data):
        '''
            Do nothing
        '''
    
    def endElement(self, name):
        '''Do nothing'''